﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Horridor
{
    class Player : DrawableObject
    {

        private DrawableObject crosshair;
        private Weapon weapon; // create something liek an inventory so you can hold multiple weapons

        public Player(Texture2D Texture)
            : base(Texture)
        {
            setPos(0, 0);
            crosshair = new DrawableObject(Game1.playerTex, 25, 25);
            weapon = new Weapon();
        }

        public new void Update(int ems)
        {
            // Aim:
            //crosshair.X = Game1.mouseState.X;// -(crosshair.Width / 2); ;
            //crosshair.Y = Game1.mouseState.Y;// -(crosshair.Height / 2);
            crosshair.setPos(Game1.mouseState.X, Game1.mouseState.Y);

            if (Game1.mouseState.LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                weapon.Shoot(originPos,new Vector2(Game1.mouseState.X, Game1.mouseState.Y));

            // movement:
            Vector2 movement = new Vector2(0,0);
            if (Game1.keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A))
                movement.X -= 1;
            if (Game1.keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D))
                movement.X += 1;
            if (Game1.keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.W))
                movement.Y -= 1;
            if (Game1.keyboardState.IsKeyDown(Microsoft.Xna.Framework.Input.Keys.S))
                movement.Y += 1;
            if (movement.Length() > 0)
            {
                movement.Normalize();
                originPos.X += (movement.X * 5);
                originPos.Y += (movement.Y * 5);
            }
            DebugLayer.ShowMessage(String.Format("X: {0} Y: {1}",drawRectangle.X,drawRectangle.Y));

            weapon.Update(ems);
        }

        public new void Draw(SpriteBatch batchy)
        {
            base.Draw(batchy);
            weapon.Draw(batchy);
            //draw crosshair
            crosshair.Draw(batchy);
        }
    }
}
